package game;

import java.util.Random;

/**
 * 敌机类
 *
 * @author zl
 */
public class EnemyPlane
        extends FlyObeject {

    int hp;
    int type;

    public EnemyPlane() {
        Random rd = new Random();
        int index = rd.nextInt(6) + 1;
        type = index;
        String path = "/picture/bullet" + (index < 10 ? "0" : "") + index + ".png";
        img = GetPicture.getImg(path);
        w = img.getWidth();
        h = img.getHeight();
        x = rd.nextInt(512 - w);
        y = -h;
        hp = 7;
    }

    public void move() {
        if (type == 5 || type == 2) {
            x -= 5;
            Random random = new Random();
            y += random.nextInt(10) + 1;
        } else if (type == 6) {
            x += 5;
            Random random = new Random();
            y += random.nextInt(10) + 1;
        } else if (type == 1) {
            Random random = new Random();
            y += random.nextInt(10) + 3;
        } else {
            Random random = new Random();
            y += random.nextInt(10) + 1;
        }
    }

    public boolean shootBy(Bullet f) {
        boolean hit = x <= f.x + f.w && x >= f.x - w && y <= f.y + f.h && y >= f.y - h;
        return hit;
    }

    public boolean hitBy(MyPlane myPlane) {
        boolean hit = x <= myPlane.x + myPlane.w && x >= myPlane.x - w && y <= myPlane.y + myPlane.h && y >= myPlane.y - h;
        return hit;
    }
}
